﻿//************************************************************************************************************
// CoNatural.Data.dll
// Author: Roger Torres
//************************************************************************************************************
// You can use, modify, and distribute the source code and executable programs based on the source code.
// This source code is provided "as is" and without warranties as to performance or merchantability. 
// The author and/or distributors of this source code may have made statements about this source code. 
// Any such statements do not constitute warranties and shall not be relied on by the user in deciding 
// whether to use this source code. This source code is provided without any express or implied warranties 
// whatsoever. Because of the diversity of conditions and hardware under which this source code may be used, 
// no warranty of fitness for a particular purpose is offered. The user is advised to test the source code 
// thoroughly before relying on it. The user must assume the entire risk of using the source code.
//************************************************************************************************************

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Reflection;

namespace CoNatural.Data {
	/// <summary>
	/// Generic interface to the underlying database management system
	/// </summary>
	public interface IDbProvider {
		/// <summary>
		/// Creates IDbConnection
		/// </summary>
		IDbConnection CreateConnection();

		/// <summary>
		/// Creates IDbCommand
		/// </summary>
		/// <returns></returns>
		IDbCommand CreateCommand();

		/// <summary>
		/// Creates Parameter from CLR data type
		/// </summary>
		/// <param name="name">The parameter name.</param>
		/// <param name="type">The CLR data type.</param>
		/// <param name="parameterAttribute">The property attributes.</param>
		/// <returns>The Parameter.</returns>
		Parameter CreateParameter(string name, Type type, ParameterAttribute parameterAttribute);

		/// <summary>
		/// Creates data parameter, handling size and precision properties (not part of the IDbDataParameter interface)
		/// </summary>
		/// <param name="name">The parameter name.</param>
		/// <param name="dbType">The parameter db type.</param>
		/// <param name="direction">The parameter direction.</param>
		/// <param name="size">The parameter size.</param>
		/// <param name="precision">The parameter precision.</param>
		/// <param name="scale">The parameter scale.</param>
		/// <param name="isNullable">The parameter nullability.</param>
		/// <param name="udtName">The parameter udt name.</param>
		/// <param name="value">The parameter value.</param>
		/// <returns>A new IDbDataParameter.</returns>
		IDbDataParameter CreateDataParameter(string name, DbType dbType, ParameterDirection direction, int size, byte precision, byte scale, bool isNullable, string udtName, object value);

		/// <summary>
		/// Generates stored procedure name from command.
		/// </summary>
		/// <param name="command">The ICommand.</param>
		/// <returns>The name of the stored procedure associated with this command.</returns>
		string ScriptName(ICommand command);

		/// <summary>
		/// Scripts batch execution of commands as stored procedures.
		/// MUST return command's output parameter values in a result set following this schema:
		///	ZeroBasedCommandIndex INT, OutputParameterName STRING, OutputParameterValue VARIANT
		/// </summary>
		/// <param name="batchCtx">The batch execution context.</param>
		/// <returns>The sql script (batch).</returns>
		string ScriptBatch(BatchExecutionContext batchCtx);
	}
}
